import businessCommonMgr from '@/biz/businessReport/businessCommon'
import houseOpt from '@/biz/option/house.js'
import ruleOpt from '@/biz/option/rule.js'

import Opt from '@/components/dt/info/Opt.js'
import tool from '@/common/tool.js'
let _this = null
let companys = []
class SearchOpt extends Opt {

  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  getCompany() {
    let opt = {
      title: '组织筛选',
      key: 'companyIds',
      placeholder: '全部',
      tree: {
        options: companys,
        saveAll: true
      }
    }
    let params = {
      isTwoLevel: true,
    }
    businessCommonMgr
      .getOrgThreeTree(params)
      .then((res) => {
        companys = res
        opt.tree.options = companys
      })
    return opt
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }


  createAll() {
    // let callTimeChange = {
    //   title: '回拨时间',
    //   placeholder: '请选择时间范围',
    //   key: 'callTime',
    //   date: {
    //     type: 'daterange',
    //     disabled: (date) => {
    //       let startDate = _this.formValidate.clueGenTime[0] ? _this.formValidate
    //         .clueGenTime[0] : ''
    //       return date.valueOf() < new Date(startDate).getTime()
    //     },
    //   },
    //   data: {
    //     to: (val) => {
    //       return {
    //         callbackStartTime: val[0],
    //         callbackEndTime: val[1]
    //       }
    //     }
    //   },
    //   disabled: true,
    // }
    this.all = [
      this.getCompany(),
      houseOpt.create({
        title: '所属案场',
        placeholder: '请输入所属案场',
        to: (info) => {
          return {
            buildingId: info.housesId
          }
        }
      }),
      // {
      //   title: '线索生成时间',
      //   placeholder: '请选择时间范围',
      //   key: 'clueGenTime',
      //   date: {
      //     type: 'daterange'
      //   },
      //   change: (val) => {
      //     console.log(val)
      //     if (val.value[0] || _this.formValidate.batch) {
      //       callTimeChange.disabled = false
      //       _this.formValidate.callTime = []
      //     } else {
      //       callTimeChange.disabled = true
      //       _this.formValidate.callTime = []
      //     }
      //   }
      // },
      // callTimeChange
      // {
      //   title: '主叫拨打时间',
      //   key: 'checkTime',
      //   placeholder: '请选择时间范围',
      //   xl: 4,
      //   date: {
      //     type: 'daterange',
      //     disabled: (date) => {
      //       return date.valueOf() > new Date().getTime()
      //     }
      //   },
      //   rules: [
      //     ruleOpt.check('日期跨度至多两年', (value) => {
      //       return value.length && tool.dateDiff(value[0], value[1]).Y >= 2
      //     })
      //   ]
      // },

    ]
  }
}

export default SearchOpt